package com.glenet.salary.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;

import com.glenet.salary.entities.HrPreSalary;
import com.glenet.salary.util.SessionFactoryUtil;

public class HrPreSalaryDao extends HrDaoSuport {

	
	@SuppressWarnings("unchecked")
	public List<HrPreSalary> list(int offset, int limit) {
		List<HrPreSalary> list = new ArrayList<HrPreSalary>();
		try {
			SqlSession session = SessionFactoryUtil.openSession();
			list = (List<HrPreSalary>) session.selectList("HrSalaryIn.select", null, new RowBounds(offset, limit));
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public int batchImport(List<HrPreSalary> list) {
		int effect = 0;
		try {
			SqlSession session = SessionFactoryUtil.getSessionFactory().openSession(ExecutorType.BATCH);
			for (HrPreSalary salaryIn : list) {
				session.insert("HrSalaryIn.insert", salaryIn);
			}
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return effect;
	}
}
